﻿// (c) Copyright Mikhail Dikov. All other rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using AjaxControlToolkit;
using System.Xml.Serialization;
using System.ComponentModel;

namespace WebPartExtenderToolkit
{
    
    public abstract class ExtenderWebPartBase : WebPart, IExtenderWebPart
    {
        protected enum ExtenderWebPartType
        {
            WebPart,
            WebPartZone
        }

        #region IExtenderWebPart Members

        // TBD: this should be a drop down with all web parts on the page
        [Category("Extender"),
        Personalizable(PersonalizationScope.Shared),
        Browsable(true),
        DisplayName("TargetControlID"),
        Description("The id of the web part to extend.")]
        public string TargetControlID { get; set;}

        public string BehaviorID { get; set; }

        protected ExtenderWebPartType TargetType { get; set; }  

        #endregion


        //TBD: Make a base WP class with the IWebEditable and IExtenderWebPart
        #region IWebEditable Members

        public override EditorPartCollection CreateEditorParts()
        {
            
            List<EditorPart> customEditorPartCollection = new List<EditorPart>();
            EditorPart editorPart;
            if (TargetType == ExtenderWebPartType.WebPartZone)
            {
                editorPart = new ZoneExtenderEditorPart();
                editorPart.ID = this.ID + "_ZoneExtenderPart";
            }
            else
            {
                editorPart = new ExtenderEditorPart();
                editorPart.ID = this.ID + "_ExtenderPart";
            }
            customEditorPartCollection.Add(editorPart);
            EditorPartCollection editorPartCollection = new EditorPartCollection(customEditorPartCollection);
            return editorPartCollection;
        }

        public override object WebBrowsableObject
        {
            get { return this; }
        }

        #endregion

    
    }
}
